package com.controller;

import com.entity.PostingVisitPrivilege;
import com.service.PostingVisitPrivilegeService;
import com.vo.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 帖子权限控制器
 *
 * @author lbb
 * @version 1.0
 * @date 2020.3.4
 */
@RestController
@RequestMapping("/api")
public class PostingVisitPrivilegeController {
	
	@Autowired
	private PostingVisitPrivilegeService postingVisitPrivilegeService;
	
	/**
	 * 添加权限
	 *
	 * @param postingId 帖子ID
	 * @param userIds   需要添加权限的用户ID
	 * @return
	 */
	@PostMapping("/postingVisitPrivilege/add")
	public ResponseVO addPostingVisitPrivilege(Integer postingId, Integer... userIds) {
		Boolean bool = postingVisitPrivilegeService.addPostingVisitPrivilege(postingId, userIds);
		ResponseVO vo = new ResponseVO();
		if (bool) {
			vo.setCode("200");
			vo.setMsg("添加成功！");
		} else {
			vo.setCode("500");
			vo.setMsg("添加失败！");
		}
		vo.setData(bool);
		return vo;
	}
	
	/**
	 * 删除权限
	 *
	 * @param postingVisitPrivilege 权限信息
	 */
	@DeleteMapping("/postingVisitPrivilege/del")
	public ResponseVO delPostingVisitPrivilege(PostingVisitPrivilege postingVisitPrivilege) {
		Boolean bool = postingVisitPrivilegeService.delPostingVisitPrivilege(postingVisitPrivilege);
		ResponseVO vo = new ResponseVO();
		if (bool) {
			vo.setCode("200");
			vo.setMsg("添加成功！");
		} else {
			vo.setCode("500");
			vo.setMsg("填完失败！");
		}
		vo.setData(bool);
		return vo;
	}
}
